#ifndef     __SCAN_UART_H
#define     __SCAN_UART_H

#include "../rtos/message_queue.h"
#include "../rtos/event_flags.h"
#include "../utils/byte_view.h"
#include "../utils/error.h"

namespace driver {

class ScanUart : private utils::NoCopyable {

public:
    static constexpr uint32_t FLAG_TC = 0x01;
    static constexpr uint32_t RECV_BUF_SIZE = 64;

    void init();

    utils::Error scan(utils::ByteView &result);

    void on_recv_idle();
    void on_dma_tc() { m_flags.set_flags(FLAG_TC); }
private:
    uint8_t m_recv_buf[RECV_BUF_SIZE];
    uint32_t m_recv_index = 0;
    rtos::MessageQueue<utils::ByteView, 3> m_mq;
    rtos::EventFlags m_flags;
};

extern ScanUart scanUart;

}

#endif
